#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char const *argv[])
{
    int fd1 = open("test.txt",O_RDONLY);

    int fd2 = open("test1.txt",O_WRONLY | O_CREAT | O_APPEND,0777);

    char buf[1024];
    int read_len;
    while ( (read_len = read(fd1, buf, 1024)) > 0)
    {
        write(fd2, buf, read_len);
        write(STDOUT_FILENO, buf, read_len); // 将读取到的内容输出到标准输出
    }
    close(fd1);
    close(fd2);
    return 0;
}
